import request from '@/utils/request'

export default class RequestBase {

  client = request
  prefix = ''
  module = ''

  constructor({ prefix, module }) {
    this.prefix = prefix
    this.module = module
  }

  listPage (data) {
    return this.startPostRequest(this.getPrefix + '/listPage', data)
  }

  getOne (id) {
    return this.startGetRequest(this.getPrefix + '/getOne', { id })
  }

  submit (data) {
    return this.startPostRequest(this.getPrefix + '/add', data)
  }

  resubmit (data) {
    return this.startPostRequest(this.getPrefix + '/edit', data)
  }

  del (ids) {
    return this.startPostRequest(this.getPrefix + '/del', ids)
  }

  audit (data) {
    return this.startPostRequest(this.getPrefix + '/audit', data)
  }

  report (data) {
    return this.startPostRequest(this.getPrefix + '/report', data)
  }

  startPostRequest (path, data) {
    return this.client.post(path, data)
  }

  startGetRequest (path, params) {
    return this.client.get(path, { params })
  }

  get getPrefix () {
    return this.prefix + '/' + this.module
  }

}
